﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Diagnostics;
using Microsoft.Windows.Controls;

using InfFront.InfoViews.Base;

namespace InfFront.InfoViews.WPF
{
    /// <summary>
    /// Interaction logic for SourceFrame.xaml
    /// </summary>
    public class BaseSourceContentFrame : UserControl
    {
        #region Private Variables
        #endregion

        #region Construction/Initialization
        public BaseSourceContentFrame()
        {
            DataContextChanged += new DependencyPropertyChangedEventHandler(this_DataContextChanged);
        }

        public InfoViewSource Source
        {
            get { return (InfoViewSource)DataContext; }
            set { DataContext = value; }
        }

        protected AppGlobals AppGlobals
        {
            get
            {
                if (DataContext != null)
                    return Source.GetAppGlobals();
                return null;
            }
        }

        #endregion

        private void this_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            Rebuild();
        }

        /// <summary>
        /// Is invoked when the frame has to be completely rebuilt
        /// </summary>
        public virtual void Rebuild()
        {
        }

        /// <summary>
        /// Is invoked when some all frame's data entries (but not the entire frame's structure) must be refreshed 
        /// </summary>
        public virtual void Refresh()
        {
            Rebuild();
        }
    }
}
